<template>
  <div>
    <el-card class="recommend-card mb-3">
      <template #header>
        <div class="card-header">
          <div class="header-left">
            <span class="icon">✨</span>
            <h3 class="title">{{ props.type }}</h3>
          </div>
          <div @click="$router.push(props.url)" class="header-right">
            <span class="more-text">更多</span>
            <el-icon class="arrow-icon"><ArrowRight /></el-icon>
          </div>
        </div>
      </template>
      
      <ul class="list">
        <li class="item" v-for="item in props.data" :key="item.id" @click="goToDetail(item)">
          <div class="view">
            <span v-if="item.playCount" class="fire-icon">🔥</span>
            <span v-else class="music-icon">🎼</span>
            <span v-if="item.playCount" class="count-text">{{ Math.floor(item.playCount / 10000) }}w</span>
            <span v-else class="count-text">{{ item.musicSize }}</span>
          </div>
          <el-image class="img" :src="item.coverImgUrl || item.img1v1Url" fit="cover">
            <template #placeholder>
              <Loading />
            </template>
          </el-image>
          <p class="name">{{ item.name }}</p>
        </li>
      </ul>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from "vue"
import Loading from "@/components/Loading/index.vue"
import { useRouter } from "vue-router"
const router = useRouter()
// 接收数据
const props = defineProps<{
  data: any
  type: string
  url: string
}>()

const goToDetail = (item: any) => {
  if (props.type !== "歌手分类") {
    router.push(`/home-music/index/detail?id=${item.id}`)
  }
}
</script>

<style scoped lang="scss">
.recommend-card {
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: none;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  
  ::v-deep(.el-card__header) {
    background: var(--gradient-music-primary);
    color: #fff;
    padding: 20px 24px;
    border-bottom: none;
    
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      
      .header-left {
        display: flex;
        align-items: center;
        gap: 12px;
        
        .icon {
          font-size: 20px;
          filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
        }
        
        .title {
          margin: 0;
          font-size: 18px;
          font-weight: 600;
          color: #fff;
        }
      }
      
      .header-right {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 16px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 20px;
        cursor: pointer;
        transition: all 0.3s ease;
        backdrop-filter: blur(10px);
        
        &:hover {
          background: rgba(255, 255, 255, 0.3);
          transform: translateY(-2px);
        }
        
        .more-text {
          font-size: 14px;
          font-weight: 500;
        }
        
        .arrow-icon {
          font-size: 16px;
          transition: transform 0.3s ease;
        }
        
        &:hover .arrow-icon {
          transform: translateX(4px);
        }
      }
    }
  }
  
  ::v-deep(.el-card__body) {
    padding: 24px;
    background: #fafbfc;
  }
}

.list {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 20px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  
  /* 滚动条样式 */
  &::-webkit-scrollbar {
    display: none;
  }
  
  .item {
    height: 140px;
    width: 140px;
    border-radius: 16px;
    justify-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    transition: all 0.3s ease;
    cursor: pointer;
    
    &:hover {
      transform: translateY(-8px);
      
      .img {
        box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
        
        ::v-deep(img) {
          transform: scale(1.05);
        }
      }
      
      .name {
        color: #409eff;
      }
    }
    
    .img {
      width: 90%;
      height: 90%;
      border-radius: 12px;
      border: 3px solid #fff;
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
      transition: all 0.3s ease;
      overflow: hidden;
      
      ::v-deep(img) {
        transition: all 0.3s ease;
        width: 100%;
        height: 100%;
      }
    }
    
    .name {
      width: 85%;
      margin-top: 12px;
      font-size: 14px;
      font-weight: 500;
      color: #303133;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: center;
      transition: color 0.3s ease;
    }
    
    .view {
      position: absolute;
      top: 8px;
      right: 20px;
      padding: 6px 10px;
      z-index: 10;
      color: #fff;
      font-size: 12px;
      display: flex;
      align-items: center;
      gap: 4px;
      background: rgba(0, 0, 0, 0.6);
      border-radius: 12px;
      backdrop-filter: blur(10px);
      border: 1px solid rgba(255, 255, 255, 0.2);
      
      .fire-icon,
      .music-icon {
        font-size: 14px;
      }
      
      .count-text {
        font-weight: 600;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
      }
    }
    
    // 第一个项目（大尺寸）
    &:nth-child(1) {
      grid-column: 1 / span 2;
      grid-row: 1 / span 2;
      height: 300px;
      width: 300px;
      
      .name {
        font-size: 16px;
        font-weight: 600;
        margin-top: 16px;
      }
      
      .view {
        right: 32px;
        top: 16px;
        padding: 8px 12px;
        font-size: 14px;
        
        .fire-icon,
        .music-icon {
          font-size: 16px;
        }
      }
      
      &:hover {
        transform: translateY(-12px);
        
        .img {
          box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
        }
      }
    }
  }
}
</style>
